using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace Indeco.G24.Web
{
    public sealed class User
    {
        private Guid userID;
        private string userFullName;
        private string userUserName;
        private string userDescription;
        private string userPassword;
        private uint idnhanvien=0;
        public User()
        { }
        private void LoadFromID()
        {
            DMS.DataService.User dataUser =new DMS.DataService.User();
            DataRow userRow = dataUser.Retrieve(userID);

            userFullName = userRow["FULLNAME"] == System.DBNull.Value ? "" : (string)userRow["FULLNAME"];
            userUserName = (string)userRow["USERNAME"];
            userDescription = userRow["DESCRIPTION"]==System.DBNull.Value ? "" : (string)userRow["DESCRIPTION"];//row.Quantity == System.BDNull ? 0 : row.Quantity
            userPassword = (string)userRow["PASSWORD"];
            idnhanvien = userRow["ID_nhanvien"] == System.DBNull.Value ? 0 : Convert.ToUInt32(userRow["ID_nhanvien"].ToString());
        }
        public User(int existingUserID)
        {
            userID = existingUserID;
            LoadFromID();
        }
        public User(DMSPrincipal existingPrincipal)
        {
            userID = ((SiteIdentity)existingPrincipal.Identity).UserID;
            LoadFromID();
        }
        public bool Update()
        {
            DMS.DataService.User dataUser = new DMS.DataService.User();
            return dataUser.Update(
                userID,
                UserName,
                PassWord,
                FullName,
                Description);
        }

        // PROPERTIES DEFINED BELOW

        public int UserID
        {
            get
            {
                return userID;
            }
            set
            {
                userID = value;
            }
        }

        public string FullName
        {
            get
            {
                return userFullName;
            }
            set
            {
                userFullName = value;
            }
        }

        public string PassWord
        {
            get
            {
                return userPassword;
            }
            set
            {
                userPassword = value;
            }
        }

        public string UserName
        {
            get
            {
                return userUserName;
            }
            set
            {
                userUserName = value;
            }
        }

        public string Description
        {
            get
            {
                return userDescription;
            }
            set
            {
                userDescription = value;
            }
        }
        public uint Id_nhanvien
        {
            get { return idnhanvien; }
            set { idnhanvien = value; }
        }
    }
}
